/*
 * @Author: Rocky 181433745@qq.com
 * @Date: 2022-12-08 08:08:30
 * @LastEditors: Rocky 181433745@qq.com
 * @LastEditTime: 2022-12-09 17:32:18
 * @FilePath: \todo-list-vue\src\store\taskStore.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { getAllTodoList, deleteTask, getWeekTask } from '../api/task'
import moment from 'moment'

export const useTaskStore = defineStore('useTaskStore', {
    // 开启数据持久化
    persist: true,
    state: () => {
        return {
            clickedDay: "",
            taskList: [
                {
                    id: 0,
                    data: "",
                    player: "",
                    startTime: "",
                    endTime: "",
                    name: "",
                    state: 0,
                    content: "",
                    categoryName: "",
                    address: ""

                },
            ],
            weekList: [
                {
                    address: "",
                    categoryName: "",
                    content: "",
                    createBy: null,
                    createTime: "",
                    delFlag: 0,
                    endTime: "",
                    id: 0,
                    name: "",
                    player: "",
                    startTime: "",
                    state: 0,
                    updateBy: null,
                    updateTime: "",
                    userId: 0
                },
            ]
        }
    },
    getters: {


    },
    actions: {
        setClickedDay(day) {
            console.log(day);
            this.clickedDay = day
            console.log(this.clickedDay);
        },
        async setTaskList(userId) {
            await getAllTodoList(userId).then((res) => {
                this.taskList = res.result
            });
        },
        async setAllWeekTask(userId) {
            await getWeekTask(userId).then((res) => {
                console.log(res);
                this.weekList = res.result
            });
        },
        async delTaskList(userID) {
            await deleteTask(userID).then(res => {
                if (res.code == 200) {
                    this.setTaskList(userID)
                }
            })
        }


    }
})